package com.kemai.designmode.ui
import android.os.Bundle
import com.kemai.common.adapter.ItemClickListener
import com.kemai.common.ui.BaseActivity
import com.kemai.designmode.R
import com.kemai.designmode.entry.Fruit
import com.kemai.designmode.factory.abstract.AbstractFactory
import com.kemai.designmode.factory.abstract.AppleAbstractFactory
import com.kemai.designmode.factory.abstract.BananaAbstractFactory
import com.kemai.designmode.factory.abstract.OrangeAbstractFactory
import com.kemai.designmode.factory.method.AppleMethodFactory
import com.kemai.designmode.factory.method.BananaMethodFactory
import com.kemai.designmode.factory.method.OrangeMethodFactory
import com.kemai.designmode.strategy.BaZheDiscount
import com.kemai.designmode.strategy.DiscountShoppingCart
import com.kemai.designmode.strategy.JiuZheDiscount
import com.kemai.designmode.strategy.OnLineShoppingCart
import com.kemai.designmode.template.CashShoppingCart

//策略模式调用(通过选择策略类，来执行不同的算法分支，其核心思想，通过注入对象来改变行为)
class StrategyActivity : BaseActivity(), ItemClickListener {
    private val studyContent = arrayOf("九折优惠","八折优惠")
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_common_content)
        findViewById()
        setTiTle("策略模式")
        setAdapterContent(studyContent,StrategyActivity@this,StrategyActivity@this)
    }

    override fun itemClick(position: Int) {
        var products = ArrayList<Fruit>()
        val appleMethodFactory = AppleMethodFactory()
        val bananaMethodFactory = BananaMethodFactory()
        val orangeMethodFactory = OrangeMethodFactory()
        val apple = appleMethodFactory.getFruit()
        val banana = bananaMethodFactory.getFruit()
        val orange = orangeMethodFactory.getFruit()
        products.add(apple)
        products.add(banana)
        products.add(orange)
        when(position){
            0->{
                val cashShoppingCart = OnLineShoppingCart(products,JiuZheDiscount())
                cashShoppingCart.submitOrder()
            }
            1->{
                val cashShoppingCart = OnLineShoppingCart(products,BaZheDiscount())
                cashShoppingCart.submitOrder()
            }
        }
    }

}